﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Lottery.Models.Home
{
    public class BaseModel
    {
        public List<Menu> MenuList { get; set; }
        public string Caption { get; set; }

        public Menu SelectMenu { get; set; }

        public void CreateMenu(bool isAmdin)
        {
            if (isAmdin)
            {
                MenuList = new List<Menu>()
                {
                    new Menu(){ Title = "高级管理" , Key = "" , SubMenu = new List<Menu>()
                    {
                        new Menu(){ Title = "用户清单" , Key = "/Home/UserList"},
                        new Menu(){ Title = "截止收单" , Key = "/Home/StopOrder"},
                        new Menu(){ Title = "高级单据查询" , Key = "/Home/AdvOrderSearch"},
                        new Menu(){ Title = "高级单据统计" , Key = "/Home/AdvOrderReport"},
                    }},
                    new Menu(){ Title = "单据管理" , Key = "" , SubMenu = new List<Menu>()
                    {
                        new Menu(){ Title = "下单" , Key = "/Home/Order"},
                        new Menu(){ Title = "单据查询" , Key = "/Home/OrderSearch"},
                        new Menu(){ Title = "单据统计" , Key = "/Home/OrderReport"},
                    }},
                };
            }
            else
            {
                MenuList = new List<Menu>()
                {
                    new Menu(){ Title = "单据管理" , Key = "" , SubMenu = new List<Menu>()
                    {
                        new Menu(){ Title = "下单" , Key = "/Home/Order"},
                        new Menu(){ Title = "单据查询" , Key = "/Home/OrderSearch"},
                        new Menu(){ Title = "单据统计" , Key = "/Home/OrderReport"},
                    }},
                    new Menu(){ Title = "其他功能" , Key = "", SubMenu = new List<Menu>()
                    {
                        new Menu(){ Title = "修改密码" , Key = "/Home/ChangePassword"},
                        new Menu(){ Title = "用户记录" , Key = "/Home/UserLog"},
                    }},
                 };
            }
        }

        public void Select(string title)
        {
            foreach (var menu in MenuList)
            {
                menu.IsSelect = false;
                if (menu.Title == title)
                {
                    menu.IsSelect = true;
                    foreach (var subMenu in menu.SubMenu)
                    {
                        subMenu.IsSelect = false;
                    }
                }
                else
                {
                    foreach (var subMenu in menu.SubMenu)
                    {
                        subMenu.IsSelect = false;
                        if (subMenu.Title == title)
                        {
                            subMenu.IsSelect = true;
                            SelectMenu = subMenu;
                            menu.IsSelect = true;
                        }
                    }
                }
            }
        }
    }
}